package com.client.controller;

import com.Emplyment.entity.QuetionCollect;
import com.Emplyment.result.Result;
import com.Emplyment.vo.QuestionBankVo;
import com.client.service.QuestionBankService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/questionbank")
public class QuestionBankController {

    @Autowired
    private QuestionBankService questionBankService;

    @GetMapping("/getallcareer")
    public Result<List<String>> getAllCareer() {
        log.info("获取所有职业");
        List<String> allCareer = questionBankService.getAllCareer();
        log.info("获取到的所有职业: " + allCareer);
        return Result.success(allCareer);
    }


    @GetMapping("/getquestionbank")
    public Result<List<QuestionBankVo>> getQuestionBank(@RequestParam String selectedCareer) {
        log.info("选择的职业: " + selectedCareer);
        List<QuestionBankVo> questionBank = questionBankService.getQuestionBank(selectedCareer);
        log.info("获取到的题库: " + questionBank);
        return Result.success(questionBank);
    }

    /**
     * 获取收藏状态
     */
    @GetMapping("/getcollectstatus")
    public Result<Integer> getCollectStatus(@RequestParam String username, @RequestParam Integer questionId) {
        log.info("获取收藏状态: " + questionId + " " + username);
        Integer collectStatus = questionBankService.getCollectStatus(questionId, username);
        return Result.success(collectStatus);
    }

    /**
     * 收藏
     */
    @PostMapping("/collect")
    @Transactional
    public Result collect(@RequestBody QuetionCollect quetionCollect) {
        log.info("收藏: " + quetionCollect);
        questionBankService.collect(quetionCollect);
        return Result.success();
    }

    /**
     * 取消收藏
     */
    @PostMapping("/canalcollect")
    @Transactional
    public Result cancelCollect(@RequestBody QuetionCollect quetionCollect) {
        log.info("取消收藏: " + quetionCollect);
        questionBankService.cancelCollect(quetionCollect);
        return Result.success();
    }

    /**
     * 获取热门问题数据
     */
    @GetMapping("/gethotquestions")
    public Result<List<QuestionBankVo>> getHotQuestions() {
        log.info("获取热门问题数据");
        List<QuestionBankVo> hotQuestions = questionBankService.getHotQuestions();
        return Result.success(hotQuestions);
    }

}
